<?php
namespace common\models;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "game_version".
 *
 * @property string $id
 * @property string $game_id
 * @property integer $mobileos_type_id
 * @property string $version_title
 * @property string $version
 * @property string $version_size
 * @property string $version_os
 * @property string $soft_url
 * @property string $create_time
 * @property string $update_time
 * @property integer $is_first
 * @property string $c_package_name
 * @property string $channelId
 */
class GameVersion extends \yii\db\ActiveRecord
{

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'game_version';
    }

    /*
     * 产生创建日期和更新日期时间戳
     */
    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'createdAtAttribute' => 'create_time',
                'updatedAtAttribute' => 'update_time'
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [
                [
                    'game_id',
                    'mobileos_type_id',
                    'create_time',
                    'update_time',
                    'is_first'
                ],
                'integer'
            ],
            [
                [
                    'version_title',
                    'version',
                    'version_size',
                    'soft_url',
                    'c_package_name'
                ],
                'required'
            ],
            [
                [
                    'version_title',
                    'version',
                    'version_size',
                    'version_os',
                    'c_package_name'
                ],
                'string',
                'max' => 100
            ],
            [
                [
                    'soft_url'
                ],
                'string',
                'max' => 255
            ],
            [
                [
                    'channelId'
                ],
                'string',
                'max' => 50
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'game_id' => '游戏ID',
            'mobileos_type_id' => '手机系统类型ID',
            'version_title' => '版本标题',
            'version' => '版本号',
            'version_size' => '版本大小',
            'version_os' => '系统信息',
            'soft_url' => '下载地址',
            'create_time' => '创建时间',
            'update_time' => '更新时间',
            'is_first' => '是否指定',
            'c_package_name' => '包名',
            'channelId' => '频道'
        ];
    }

    // relationship
    /**
     * 所属游戏
     */
    public function getGame()
    {
        return $this->hasOne(Game::className(), [
            'game_id' => 'game_id'
        ]);
    }

    /**
     * 所属游戏信息
     */
    public function getGameInfo()
    {
        return $this->hasOne(GameInfo::className(), [
            'game_id' => 'game_id'
        ]);
    }
}
